<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单据提交列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="msg"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="statusCode" >
                                    <option value=>全部</option>
                                    <option value=0>新建</option>
                                    <option value=1>提交</option>
                                    <option value=2>已审核</option>
                                    <option value=3>驳回</option>
                                </select>
                            </li>
                            <li>
                                <label>科室：</label>
                                <select name="deptId">
                                    <option th:each="dept:${depts}" th:value="${dept.deptId}" th:text="${dept.deptName}" ></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-info single disabled" onclick="printFlow()" >
                    <i class="fa fa-print"></i> 打印
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/flow";

       $(document).ready(function () {
            $('.summernote').summernote({
                lang: 'zh-CN'
            });
        });

      function editNoteOpen(workId){
             var url= prefix+"/editNote?workId="+workId;
             $.modal.openTab("查看", url);

        }
        function printFlow() {
            var row =$("#bootstrap-table").bootstrapTable('getSelections')[0];
            if ($.common.isEmpty(row)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.openTab("需求打印", prefix+"/print/"+row.workId);
        }
        function commit(id) {
            $.modal.confirm("一旦提交将不可撤回是否继续？", function() {
                $.ajax({
                    url: prefix+"/updateStatus?ids="+id+"&status="+1,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'GET',
                    success: function (result) {
                        $("#bootstrap-table").bootstrapTable('refresh');
                        $.modal.alertSuccess(result);
                    }
                });
            });
        }

        $(function() {
            var options = {
                url: prefix + "/listWithAuth",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "单据提交",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'workId',
                    title: '',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '科室名称'
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'naEmpCre',
                    title: '创建人'
                },
                {
                    field: 'dtSysCre',
                    title: '创建日期'
                },
                 {
                    field: 'statusCode',
                   title: '状态',
                        formatter: function (value, item, index) {
                            if (item.statusCode == 0) {
                                return "新建";
                            } else if (item.statusCode == 1) {
                                return "<span style='color:red'>提交</span>";
                            } else if (item.statusCode == 2) {
                                return "<span style='color:red'>已审核</span>";
                            } else if (item.statusCode == 3) {
                                return "<span style='color:red'>驳回</span>";
                            } else if (item.statusCode == 4) {
                                return "<span style='color:red'>开发中</span>";
                            } else if (item.statusCode == 5) {
                                return "<span style='color:red'>已完成</span>";
                            }
                        }
                },
                {
                    field: 'euFreq',
                    title: '频次',
                    formatter: function (value, item, index) {
                        if (item.euFreq == 1) {
                            return "小于一月";
                        } else if (item.euFreq == 2) {
                            return "小于一季";
                        } else if (item.euFreq == 3) {
                            return "小于一年";
                        } else if (item.euFreq == 4) {
                            return "仅此一次";
                        }
                    }
                },
                {
                    field: 'fgUrgent',
                    title: '加急标志',
                    formatter: function (value, item, index) {
                        if (item.fgUrgent == 0) {
                            return "正常";
                        } else if (item.fgUrgent == 1) {
                            return "<span style='color:red'>加急</span>";
                        }
                    }
                },
                {
                    field: 'lastDate',
                    title: '最后日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                         actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="editNoteOpen(\'' + row.workId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                         if (row.statusCode == 0 || row.statusCode == 3 ) {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.workId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="commit(\'' + row.workId + '\')"><i class="fa fa-hand-grab-o"></i>提交</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.workId + '\')"><i class="fa fa-remove"></i>删除</a>');
                         }
       return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>